//
//  KeybordShowSingle.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/10/30.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "KeybordShowSingle.h"

@implementation KeybordShowSingle
+ (instancetype)mainKeybordShowSingle
{
    static KeybordShowSingle *keybordShowSingle;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        keybordShowSingle = [[KeybordShowSingle alloc] init];
    });
    return keybordShowSingle;
}

- (instancetype)init
{
    if (self = [super init])
    {
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center  addObserver:self selector:@selector(keyboardDidShow:)  name:UIKeyboardDidShowNotification  object:nil];
        [center addObserver:self selector:@selector(keyboardDidHide)  name:UIKeyboardWillHideNotification object:nil];
        self.keyboardHeight = 0;
    }
    return self;
}

-(void)keyboardDidShow:(NSNotification *)not
{
    NSDictionary *userInfo = [not userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    self.keyboardHeight = keyboardRect.size.height;
}

- (void)keyboardDidHide
{
    self.keyboardHeight = 0;
}

- (CGFloat)keyboardHeight
{
    return _keyboardHeight;
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
